enum StorageType {
  Local,
  Session,
}

class FyStorge {
  storage: Storage

  constructor(type: StorageType) {
    this.storage = type === StorageType.Local ? localStorage : sessionStorage
  }
  set(key: string, value: any) {
    this.storage.setItem(key, JSON.stringify(value))
  }
  get(key: string) {
    const value = this.storage.getItem(key)
    if (value) {
      return JSON.parse(value)
    }
  }
  remove(key: string) {
    this.storage.removeItem(key)
  }
  clear() {
    this.storage.clear()
  }
}

const Storage = new FyStorge(StorageType.Local)
// const SessionStorage = new FyStorge(StorageType.Session)

export default Storage
